﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfApp001.Core;
using WpfApp001.Model;

namespace WpfApp001.ViewModel
{
    public class CourseVM: NotifyBase
    {

        public CommandBase CoursesFilterCommand { get; set; }

        public List<CourseModel> AllCourses { get; set; }

        public CourseVM() {

            this.CoursesFilterCommand = new CommandBase();
            this.CoursesFilterCommand.DoExecute = new Action<object>(DoFilter);
            this.CoursesFilterCommand.DoCanExecute = new Func<object, bool>(o => true);

            this.CourseCategory = new List<RadioInfo>()
            {
                new RadioInfo() {Name="全部",IsSelected=true},
                new RadioInfo() {Name="公开课",IsSelected=false},
                new RadioInfo() {Name="VIP课程",IsSelected=false},
            };

            this.TechnologyCategory = new List<RadioInfo>()
            {
                new RadioInfo() {Name="全部",IsSelected=true},
                new RadioInfo() {Name="C#",IsSelected=false},
                new RadioInfo() {Name="Asp.Net",IsSelected=false},
                new RadioInfo() {Name="微服务",IsSelected=false},
                new RadioInfo() {Name="Java",IsSelected=false},
            };

            this.Teacher = new List<RadioInfo>()
            {
                new RadioInfo() {Name="全部",IsSelected=true},
                new RadioInfo() {Name="马云",IsSelected=false},
                new RadioInfo() {Name="雷军",IsSelected=false},
                new RadioInfo() {Name="马化腾",IsSelected=false},
                new RadioInfo() {Name="周鸿祎",IsSelected=false},
            };

            AllCourses = new List<CourseModel>()
            {
                new CourseModel(){Title="C#/.Net构造师蜕变班",Teacher="马云",TechnologyCategory="C#",Pic="/Resource/Images/1.jpg",CourseCategory="公开课",Info="朝夕教育，专注于IT类在线教育，注重服务与口碑，解决升职与加薪难题。课程体系覆盖C#/.NET零基础就业、进阶高级开发、蜕变架构师全周期，以及上位机、AutoCAD、Java进阶等，致力于打造高品质在线教育"},
                new CourseModel(){Title="C#/.Net构造师蜕变班",Teacher="雷军",TechnologyCategory="C#",Pic="/Resource/Images/2.jpg",CourseCategory="公开课",Info="朝夕教育，专注于IT类在线教育，注重服务与口碑，解决升职与加薪难题。课程体系覆盖C#/.NET零基础就业、进阶高级开发、蜕变架构师全周期，以及上位机、AutoCAD、Java进阶等，致力于打造高品质在线教育"},
                new CourseModel(){Title="C#/.Net构造师蜕变班",Teacher="马化腾",TechnologyCategory="Java",Pic="/Resource/Images/3.jpg",CourseCategory="公开课",Info="朝夕教育，专注于IT类在线教育，注重服务与口碑，解决升职与加薪难题。课程体系覆盖C#/.NET零基础就业、进阶高级开发、蜕变架构师全周期，以及上位机、AutoCAD、Java进阶等，致力于打造高品质在线教育"},
                new CourseModel(){Title="C#/.Net构造师蜕变班",Teacher="周鸿祎",TechnologyCategory="Java",Pic="/Resource/Images/4.jpg",CourseCategory="公开课",Info="朝夕教育，专注于IT类在线教育，注重服务与口碑，解决升职与加薪难题。课程体系覆盖C#/.NET零基础就业、进阶高级开发、蜕变架构师全周期，以及上位机、AutoCAD、Java进阶等，致力于打造高品质在线教育"},
            
            };

            this.CourseModels = AllCourses.ToList();

        }


        public List<RadioInfo> courseCategory;
        public List<RadioInfo> CourseCategory
        {
            get { return courseCategory; }
            set { courseCategory = value;this.DoNotify(); }
        }


        public List<RadioInfo> technologyCategory;
        public List<RadioInfo> TechnologyCategory
        {
            get { return technologyCategory; }
            set { technologyCategory = value; this.DoNotify(); }
        }


        public List<RadioInfo> teacher;
        public List<RadioInfo> Teacher
        {
            get { return teacher; }
            set { teacher = value; this.DoNotify(); }
        }


        public List<CourseModel> courseModels;
        public List<CourseModel> CourseModels
        {
            get { return courseModels; }
            set { courseModels = value; this.DoNotify(); }
        }




        private void DoFilter(object obj)
        {
            string teacher = Teacher.Where(m => m.IsSelected).Select(m => m.Name).FirstOrDefault();
            string technology = TechnologyCategory.Where(m => m.IsSelected).Select(m => m.Name).FirstOrDefault();
            string courseCategory = CourseCategory.Where(m => m.IsSelected).Select(m => m.Name).FirstOrDefault();

            var currentList = AllCourses.Where(m => true);

            if (teacher!="全部")
            {
                currentList = currentList.Where(m => m.Teacher == teacher).ToList();
            }

            if (technology != "全部")
            {
                currentList = currentList.Where(m => m.TechnologyCategory == technology).ToList();
            }

            if (courseCategory != "全部")
            {
                currentList = currentList.Where(m => m.CourseCategory == courseCategory).ToList();
            }

            this.CourseModels = currentList.ToList();

        }


        

    }
}
